package com.scu.servlet;

import com.scu.dao.PostDao;
import com.scu.entity.Post;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet(name = "AddPostServlet", value = "/AddPostServlet")
public class AddPostServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String post_id = request.getParameter("post_id");
        String post_content = request.getParameter("post_content");
        String user_id = request.getParameter("user_id");
        String date = request.getParameter("date");
        String type = request.getParameter("type");
        String post_title = request.getParameter("post_title");
        String is_illegal = request.getParameter("is_illegal");


        Post post = new Post();
        post.setPost_id(Integer.parseInt(post_id));
        post.setPost_content(post_content);
        post.setUser_id(Integer.parseInt(user_id));
        post.setIs_illegal(Integer.parseInt(is_illegal));
        post.setDate(date);
        post.setType(type);
        post.setPost_title(post_title);







        System.out.println(post);
        try {
            new PostDao().insert(post);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
